package com.buobao.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buobao.entity.Test;
import com.buobao.mapper.TestMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TestService {
    @Resource
    private TestMapper testMapper;


    @Transactional
    public void batchInport(){
        for (int i = 0; i < 5; i++) {
//            if (i==3) {
//                throw new RuntimeException("测试异常");
//            }
            testMapper.insertSample();
        }
    }

    public Test selectById(Integer id) {
        return testMapper.selectById(id); //这里selectbyid方法来自 BaseMapper，也就是mybatis plus自动创建的方法
    }

    public void insert(Test test) {
        testMapper.insert(test);
    }

    public List<Test> selectList() {
        QueryWrapper<Test> queryWrapper = new QueryWrapper<Test>();
        queryWrapper.eq("id", 29);
        queryWrapper.gt("id", 35);
        return testMapper.selectList(queryWrapper);
    }
}
